package com.shaozj.redis.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.CaffeineSpec;
import org.springframework.beans.factory.xml.PluggableSchemaResolver;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;

import java.util.concurrent.TimeUnit;

@AutoConfiguration
@EnableCaching
public class CacheConfig {

    @Bean
    public Cache<Object, Object> caffeine() {
        return Caffeine.newBuilder()
                // 设置最后一次写入或访问后经过固定时间过期
                .expireAfterAccess(30, TimeUnit.SECONDS)
                //初始缓存空间大小
                .initialCapacity(100)
                //缓存最大条数
                .maximumSize(1000)
                .build();
    }

    public CacheManager cacheManager() {
//        return new CacheManager();
        return null;
    }
}
